# Copyright 2008 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Block monitoring test commits

This is used to test commits and have them be rejected by the last hook in
the chain (this one) so that we don't create a lot of revisions due to
monitoring
"""


import svn.fs

reject_propname = "gvn:block-this-commit"

def RunHook(hi, logger):
  """Implements gvn.hooks.runner's RunHook interface

  Returns:
    -1: pass and bypass other hooks
    0: pass
    1: fail
    "string": fail and print string to the user
  """

  props = svn.fs.txn_proplist(hi.txn, hi.pool)
  logger.debug("got rev props %s" % (str(props)))

  if svn.fs.txn_prop(hi.txn, reject_propname, hi.pool) is not None:
    return("Rejecting commit as requested by revprop %s" % reject_propname)

  return 0
